/*
 * HighScore - A table containing high scores
 *
 * Copyright 2008 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

class HighScore
{

	public static inline var hs_name = 1;
	public static inline var hs_group = 2;
	public static inline var hs_allscores = 3;
	public static inline var hs_recordingid = 3;

	public static inline var entriestopull = 20;

	public var style : Int;
	public var stringdata : String;
	public var daydata : Int;
	public var contents : Array<ScoreRow>;

	public function new(style : Int,
						stringdata : String, daydata : Int,
						contents : Array<ScoreRow>)
	{
		this.style = style;
		this.stringdata = stringdata;
		this.daydata = daydata;
		this.contents = contents;
	}

	#if neko
	public static function generatescores(style : Int, 
							stringdata : String, daydata : Int)
	{
		
		stringdata = Encoder.encode(stringdata);
		
		switch(style)
		{
			case(hs_name):
				// SELECT * FROM scores WHERE day==daydata AND name==stringdata ORDER BY score DESC
				// best = result[0]
				// SELECT * FROM scores WHERE day==daydata AND score>=best LIMIT 10 asc
				// SELECT * FROM scores WHERE day==daydata AND score<=best LIMIT 10 DESC
				// filter duplicates in results
				// append the other matches of name
			case(hs_recordingid):
				// SELECT * FROM scores WHERE day==daydata AND recordingid==stringdata ORDER BY score DESC
				// best = result[0]
				// SELECT * FROM scores WHERE day==daydata AND score>=best LIMIT 10 asc
				// SELECT * FROM scores WHERE day==daydata AND score<=best LIMIT 10 DESC
				// filter duplicates in results			
			case(hs_group):
				// SELECT * FROM scores WHERE day==daydata AND group==stringdata ORDER BY score DESC
			case(hs_allscores):
				// SELECT * FROM scores WHERE day==daydata ORDER BY score DESC
		}
	}
	
	#end

}

class ScoreRow
{

	public var recordingid : Int;
	public var mapid : Int;
	public var highestwave : Int;
	public var framessurvived : Int;
	public var playername : String;
	public var groupname : String;
	
	public function new(recordingid : Int,
						mapid : Int,
						highestwave : Int,
						framessurvived : Int,
						playername : String,
						groupname : String)
	{
		this.recordingid = recordingid;
		this.mapid = mapid;
		this.highestwave = highestwave;
		this.framessurvived = framessurvived;
		this.playername = playername;
		this.groupname = groupname;
	}
	
}
